package com.aiju.widgit.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.aiju.app.IDialogSimpleListener;
import com.aiju.base.R;
import com.aiju.base.dialog.BaseDialog;
import com.aiju.common.PixValue;

/**
 * @author: 佐为
 * @date: 2016-12-08 10:51
 * @version: V1.0
 * @Description: 描述
 */
public class MsgDialog extends BaseDialog implements View.OnClickListener{

    private TextView titleTextView;
    private TextView contentTextView;
    private TextView leftTextView;
    private TextView rightTextView;

    public MsgDialog(Context context) {
        super(context);
    }

    @Override
    protected int getDialogStyleId() {
        return R.style.dialog;
    }

    @Override
    protected View getView() {
        View inflate = mLayoutInflater.inflate(R.layout.dialog_msg, null);
        titleTextView = (TextView) inflate.findViewById(R.id.tv_dialog_title);
        contentTextView = (TextView) inflate.findViewById(R.id.tv_dialog_content);
        leftTextView = (TextView) inflate.findViewById(R.id.tv_dialog_left);
        rightTextView = (TextView) inflate.findViewById(R.id.tv_dialog_right);
        leftTextView.setOnClickListener(this);
        rightTextView.setOnClickListener(this);
        return inflate;
    }

    /**
     * 设置对话框LayoutParams
     *
     * @return
     */
    public MsgDialog setLayoutParams() {
        WindowManager.LayoutParams lp = getDialogWindow().getAttributes();
        lp.width = PixValue.dp.valueOf(317);
        lp.height = PixValue.dp.valueOf(165);
        getDialogWindow().setGravity(Gravity.CENTER);
        getDialogWindow().setAttributes(lp);
        return this;
    }

    public MsgDialog setTitileText(String titile) {
        this.titleTextView.setText(titile);
        return this;
    }

    public MsgDialog setContentText(String titile) {
        this.contentTextView.setText(titile);
        return this;
    }

    public MsgDialog setLeftText(String leftText) {
        this.leftTextView.setText(leftText);
        return this;
    }

    public MsgDialog setRightText(String rightText) {
        this.rightTextView.setText(rightText);
        return this;
    }

    private IDialogSimpleListener mOnSimpleClick;

    public MsgDialog setDialogSimpleListener(IDialogSimpleListener onSimpleClick) {
        this.mOnSimpleClick = onSimpleClick;
        return this;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.tv_dialog_left) {
            if (mOnSimpleClick != null) {
                mOnSimpleClick.onCancel(v);
                dismiss();
            }
        } else if (i == R.id.tv_dialog_right) {
            if (mOnSimpleClick != null) {
                mOnSimpleClick.onConfirm(v);
                dismiss();
            }
        }
    }

}
